#include<bits/stdc++.h>
#define sd(n) scanf("%d",&n) 
#define sld(n) scanf("%lld",&n)
#define push_back pb;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define pii pair<int, int>;
#define vi vector<int>;
#define yesno(condition) if(condition)cout<<"YES\n";else cout<<"NO\n";
typedef long long int ll;
using namespace std;
//----------------------------------------------------------------------------//

void solve()
{
	ll l, r,m;
	ll cnt=0;
	sld(l), sld(r);
	for (int i = l; i <= r; i++) cnt += i;
	sld(m);
	while (m--)
	{
		ll x;//x是询问的数
		sld(x);
		if (cnt % x == 0) puts("0");
		else puts("1");

	}

}

int main()
{
	int t;
	sd(t);
	while (t--)
	{
		solve();
	}

	return 0;
}
